<?php
/**
 * Created by PhpStorm.
 * User: cc
 * Date: 2021/4/21
 * Time: 2:55 下午
 */

namespace app\common\cachemodel;

use app\common\model\BaseCache;
use XznsTools\cache\CacheManage;

/**
 * Class MapRecodeBack
 * @package app\common\cachemodel
 */
class MapRecodeBack extends BaseCache
{
    protected $table = 'wechat_backup_07_18_14_43_00.app_map_recode_back';
    protected $cacheModel = 'map.map_recode_back';

    /**
     * 添加结果数据
     * @param $data
     * @return bool
     */
    public function saveData($data)
    {
        try
        {
            $id = $this->insertGetId($data);
        }
        catch (\Exception $e)
        {
            return false;
        }
        return $id;
    }

    /**
     * 更新结果数据
     * @param $id
     * @param $data
     * @return bool
     */
    public function updateData($id, $data)
    {
        try
        {
            $this->where('id', $id)->update($data);
            CacheManage::getInstance()->setCacheConfig($this->cacheModel, $id)->rmCache();

        }
        catch (\Exception $e)
        {
            return false;
        }
        return true;
    }

    /**
     * 批量获取地图解锁结果信息
     * @param $ids
     * @param $type
     * @param $sortType
     * @return array|false|string|void
     */
    public function getInfoByIdsInData($ids, $type, $sortType)
    {
        try
        {
            $data = $this->where(['id' => ['in', $ids]])->column('recode_info', 'id');
        }
        catch (\Exception $e)
        {
            $data = [];
        }
        return $data;
    }
}
